<?php


namespace app\api\lists;


use app\common\model\task\Task;

class TaskLists extends BaseShopDataLists
{
    /**
     * @notes 搜索条件
     * @return array
     * @author ljj
     * @date 2022/2/17 5:18 下午
     */
    public function setSearch(): array
    {
        return array_diff(array_keys($this->params), ['page_no', 'page_size']);
    }

    /**
     * @notes 获取违章数据
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * @author ljj
     * @date 2022/2/17 5:17 下午
     */
    public function lists(): array
    {
        $lists = Task::field('id,text,address,uri,latitude,longitude,create_time')
            ->withSearch($this->setSearch(), $this->params)
            ->limit($this->limitOffset, $this->limitLength)
            ->where('source',0)
            ->where('user_id', 0)
            ->select()
            ->toArray();
        return $lists;
    }

    /**
     * @notes 服务总数
     * @return int
     * @author ljj
     * @date 2022/2/17 5:17 下午
     */
    public function count(): int
    {
        return Task::withSearch($this->setSearch(), $this->params)
            ->count();
    }
}